#include "libLUI_in.h"

struct LUILabelData
{
	wchar_t		*label_text ;
} ;

static funcLUIDrawControlProc LUIDrawLabelProc ;
void LUIDrawLabelProc( struct LUIControl *control )
{
	struct LUILabelData		*label_data = LUIGetControlData(control) ;
	struct LUIWindow		*window = control->window ;
	struct LUIWindowsManager	*windows_manager = window->windows_manager ;
	struct LUIRectangle		draw_rect ;
	
	if( TEST_PROPERTY(control->properties,LUICONTROL_PROPERTY_SHOW) )
	{
		if( label_data->label_text )
		{
			int	align_style = LUICONTROL_STYLE_TEXTALIGN_LEFT ;
			
			draw_rect.left = window->window_rect.left + control->control_relative_rect.left ;
			draw_rect.top = window->window_rect.top + window->titlebar_rect.height + control->control_relative_rect.top ;
			draw_rect.width = control->control_relative_rect.width ;
			draw_rect.height = control->control_relative_rect.height ;
			
			if( TEST_PROPERTY(LUIGetControlStyles(control),LUICONTROL_STYLE_TEXTALIGN_MIDDLE) )
				align_style = LUICONTROL_STYLE_TEXTALIGN_MIDDLE ;
			else if( TEST_PROPERTY(LUIGetControlStyles(control),LUICONTROL_STYLE_TEXTALIGN_RIGHT) )
				align_style = LUICONTROL_STYLE_TEXTALIGN_RIGHT ;
			
			DRAW_TEXT( windows_manager , window->window_rect , draw_rect , label_data->label_text , window->font_size , align_style , & (control->control_font_color) );
		}
	}
	
	return;
}

static funcLUIControlEventProc LUILabelEventProc ;
int LUILabelEventProc( struct LUIControl *control , struct LUIEvent *event )
{
	/*
	struct LUILabelData		*label_data = LUIGetControlData(control) ;
	struct LUIWindow		*window = control->window ;
	struct LUIWindowsManager	*windows_manager = window->windows_manager ;
	*/
	
	if( event->device == LUIDEVICE_MOUSE )
	{
	}
	
	return 0;
}

struct LUIControl *LUICreateLabelControl( struct LUIWindow *window , struct LUIRectangle control_rect , int styles , int properties , wchar_t *label_text )
{
	struct LUIControl	*control = NULL ;
	struct LUILabelData	*label_data = NULL ;
	
	label_data = (struct LUILabelData *)malloc( sizeof(struct LUILabelData) ) ;
	if( label_data == NULL )
		return NULL;
	memset( label_data , 0x00 , sizeof(struct LUILabelData) );
	
	if( label_text )
	{
		label_data->label_text = wcsdup( label_text ) ;
		if( label_data->label_text == NULL )
		{
			free( label_data );
			return NULL;
		}
	}
	
	control = LUICreateControl( window , control_rect , styles , properties , LUICONTROL_TYPE_LABEL , label_data , & LUIDrawLabelProc ) ;
	if( control == NULL )
	{
		free( label_data->label_text );
		free( label_data );
		return NULL;
	}
	
	LUISetControlEventProc( control , & LUILabelEventProc );
	
	return control;
}

int LUIDestroyLabelControl( struct LUIControl *control )
{
	free( control->data );
	
	LUIDestroyControl( control );
	
	return 0;
}

